unit Camera;

interface
 uses
  direct3D9,D3DX9,DXTypes,Config;

 type

Tcamera = Class
 public
  constructor Create;
  function GetMatView: D3DMATRIX;
  procedure Up;
  procedure Down;
  procedure Left;
  procedure Right;
  procedure ZoomIn;
  Procedure ZoomOut;
  Procedure RotateTrigo;
  Procedure RotateAntiTrigo;

 private
  x,y,z: single;
  a,b:single;
end;

implementation

constructor Tcamera.Create;
begin
 x:=0;
 y:=0;
 z:=8;
 a:=0;
 b:=2;
end;

function Tcamera.GetMatView :D3Dmatrix;
begin
 D3DXMatrixLookAtLH(Result,
                    D3DXVector3( x+a, z , y+b),
                    D3DXVector3(  x , 0 ,  y ),
                    D3DXVector3( 0, 1, 0) );
end;

procedure Tcamera.up;
begin
 if y < mapsize then
  y:= y + 0.1;
end;
procedure Tcamera.down;
begin
 if y > -mapsize then
  y:= y - 0.1
end;
procedure Tcamera.left;
begin
 if x > -mapsize then
  x:= x - 0.1;
end;
procedure Tcamera.right;
begin
 if x < mapsize  then
  x:=x+0.1
end;
procedure Tcamera.ZoomIn;
begin
 if z>0 then
  z:=z-1
end;
Procedure TCamera.ZoomOut;
begin
 if z<75 then
  z:=z+1;
end;

Procedure Tcamera.RotateTrigo;
begin
 if b <> 0 then begin      // Cam Nord ou Sud
  a:= b;
  b:= 0;
 end else begin
  b:= -a;
  a:= 0;
 end;
end;

Procedure Tcamera.RotateAntiTrigo;
begin
 if a <> 0 then begin      // Cam Est ou Ouest
  b:= a;
  a:= 0;
 end else begin
  a:= -b;
  b:= 0;
 end;
end;
end.
